﻿using UnityEngine;
using System.Collections;

///Developed By Indie Studio
///https://assetstore.unity.com/publishers/9268
///www.indiestd.com
///info@indiestd.com

namespace IndieStudio.BugsBang.Utility
{
	[DisallowMultipleComponent]
	public class AudioSources : MonoBehaviour
	{
		/// <summary>
		/// The audio sources references.
		/// First Audio Souce used for the music
		/// Second Audio Souce used for the sound effects
		/// </summary>
		private AudioSource[] audioSources;

		//AudioClips references
		public AudioClip backgroundMusic;
		public AudioClip buttonClickSFX;
		public AudioClip dropStarSFX;
		public AudioClip increaseSFX;
		public AudioClip lockedSFX;
		public AudioClip killBoosterSFX;
		public AudioClip completedSFX;
		public AudioClip fingerPrintSFX;
		public AudioClip objectExplodeSFX;
		public AudioClip awwSFX;
		public AudioClip [] destroySFX;

		/// <summary>
		/// This Gameobject defined as a Singleton.
		/// </summary>
		public static AudioSources instance;

		void Awake ()
		{
			if (instance == null) {
				instance = this;
				audioSources = GetComponents<AudioSource> ();
				SetUpMuteValues ();
				DontDestroyOnLoad (gameObject);
			} else {
				Destroy (gameObject);
			}
		}

		void Start(){
			//Play the background music clip on start
			PlayBackgroundMusic ();
		}

		/// <summary>
		/// Set up the mute values for sfx, music audio sources.
		/// </summary>
		private void SetUpMuteValues ()
		{
			MusicAudioSource ().mute = DataManager.GetMusicMuteValue();
			SFXAudioSource ().mute = DataManager.GetSFXMuteValue();
		}

		/// <summary>
		/// Play the given SFX clip.
		/// </summary>
		/// <param name="clip">The Clip reference.</param>
		/// <param name="Stop Current Clip">If set to <c>true</c> stop current clip.</param>
		public void PlaySFXClip (AudioClip clip, bool stopCurrentClip)
		{
			if (clip == null) {
				return;
			}
			if (stopCurrentClip) {
				SFXAudioSource ().Stop ();
			}
			SFXAudioSource ().PlayOneShot (clip);	
		}

		/// <summary>
		/// Returns the Audio Source of the Music.
		/// </summary>
		/// <returns>The Audio Source of the Music.</returns>
		public AudioSource MusicAudioSource ()
		{
			return audioSources [0];
		}

		/// <summary>
		/// Returns the Audio Source of the Sound Effects.
		/// </summary>
		/// <returns>The Audio Source of the Sound Effects.</returns>
		public AudioSource SFXAudioSource ()
		{
			return audioSources [1];
		}

		/* List of play methods */

		public void PlayBackgroundMusic ()
		{
			MusicAudioSource ().clip = backgroundMusic;
			MusicAudioSource ().Play ();
		}

		public void PlayIncreaseSFX ()
		{
			PlaySFXClip (increaseSFX, false);
		}

		public void PlayDestroySFX ()
		{
			//Get random clip index from the array
			int index = -1;
			if(destroySFX.Length!=0)
				index = Random.Range (0, destroySFX.Length);

			if(index!=-1)
				PlaySFXClip (destroySFX[index], false);
		}

		public void PlayKillBoosterSFX ()
		{
			PlaySFXClip (killBoosterSFX, false);
		}

		public void PlayDropStarSFX ()
		{
			PlaySFXClip (dropStarSFX, false);
		}

		public void PlayLockedSFX ()
		{
			PlaySFXClip (lockedSFX, false);
		}

		public void PlayCompletedSFX ()
		{
			PlaySFXClip (completedSFX, false);
		}

		public void PlayFingerPrintSFX ()
		{
			PlaySFXClip (fingerPrintSFX, false);
		}

		public void PlayButtonClickSFX ()
		{
			PlaySFXClip (buttonClickSFX, false);
		}

		public void PlayObjectExplodeSFX ()
		{
			PlaySFXClip (objectExplodeSFX, false);
		}

		public void PlayAWWSFX ()
		{
			PlaySFXClip (awwSFX, false);
		}

        public void TEXT1()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }
        public void TEXT2()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }
        public void TEXT3()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }

        public void TEXT4()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }

        public void TEXT5()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }

        public void TEXT6()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }

        public void TEXT8()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }

        public void TEXT9()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }

        public void TEXT10()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }

        public void TEXT11()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }

        public void TEXT12()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }

        public void TEXT13()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }

        public void TEXT14()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }

        public void TEXT15()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }

        public void TEXT16()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }

        public void TEXT17()
        {
            int textNum = 1;
            if (textNum == 1)
            {
                textNum = 2;
            }
        }

    }
}

